﻿<phone:PhoneApplicationPage xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"  
    x:Class="MyMeetup.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71"
                            xmlns:ig="clr-namespace:Infragistics.Controls.Interactions;assembly=InfragisticsWP7.Controls.Interactions.XamRating.v11.2"
                            xmlns:telerikPrimitives="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Primitives"
                            mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True" shell:SystemTray.Opacity="0"
    DataContext="{Binding MainPageViewModel, Source={StaticResource Locator}}">
	
        
    

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <cmd:EventToCommand Command="{Binding LoadedCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>


    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">

        <Grid.Resources>
            <Style x:Key="DataBoundListBoxCheckBoxStyle" TargetType="telerikPrimitives:ItemCheckBox">
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}" />
                <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}" />
            </Style>

            <DataTemplate x:Key="DataBoundListBoxItemTemplate">
                <Grid Margin="0,0,0,12">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Image Width="99" Height="99" Source="{Binding group_photo.thumb_link}" Stretch="UniformToFill"/>
                    <StackPanel Margin="12,0,0,0" Grid.Column="1">
                        <TextBlock FontSize="{StaticResource PhoneFontSizeMedium}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" Text="{Binding name}" TextWrapping="Wrap"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <TextBlock x:Name="ApplicationTitle" Margin="24,17,0,0" Text="{Binding ApplicationTitle}" Style="{StaticResource PhoneTextNormalStyle}"/>

        <Grid Grid.Row="1">
        <!--Pivot Control-->
            <controls:Pivot Name="homePivot" Margin="0,-12,0,0" >
            
                <controls:PivotItem Header="news">
                <ListBox Name="newsList" ItemsSource="{Binding LatestNews}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Border Padding="15">
                                <StackPanel Orientation="Horizontal" Height="Auto" >
                                    <Image Source="{Binding photo_url}" Height="60" Width="60" Stretch="UniformToFill"  VerticalAlignment="Top" HorizontalAlignment="Left"/>
                                    <StackPanel Orientation="Vertical" >
                                        <TextBlock Text="{Binding FriendlyMessage}" Width="350" Padding="10,0,0,0" TextWrapping="Wrap"/>
                                        
                                        <TextBlock Text="{Binding FriendlyComment}" Width="350" Padding="20,0,0,0" TextWrapping="Wrap" FontSize="16"/>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </DataTemplate>                       
                    </ListBox.ItemTemplate>
                    </ListBox>
            </controls:PivotItem>

                <controls:PivotItem Header="my groups">
                    <telerikPrimitives:RadDataBoundListBox Margin="12,6,12,0"
                                                        x:Name="DataBoundListBox1"
                                                        ItemsSource="{Binding UserGroups}"
                                                        IsCheckModeEnabled="False"
                                                        CheckBoxStyle="{StaticResource DataBoundListBoxCheckBoxStyle}"
                                                        ItemTemplate="{StaticResource DataBoundListBoxItemTemplate}"
                                                           SelectedItem="{Binding SelectedGroup, Mode=TwoWay}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Tap">
                                <cmd:EventToCommand Command="{Binding GroupPageCommand, Mode=OneWay}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </telerikPrimitives:RadDataBoundListBox>
                </controls:PivotItem>


                <controls:PivotItem Header="upcoming events">

                <ListBox ItemsSource="{Binding UpcomingEvents}" SelectedItem="{Binding SelectedEvent, Mode=TwoWay}" ItemContainerStyle="{StaticResource SingleItemList}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Tap">
                            <cmd:EventToCommand Command="{Binding EventPageCommand, Mode=OneWay}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <toolkit:ContextMenuService.ContextMenu>
                                    <toolkit:ContextMenu>
                                        <toolkit:MenuItem Header="checkin" Command="{Binding MainPageViewModel.CheckinCommand, Source={StaticResource Locator}}" CommandParameter="{Binding}" />
                                        <toolkit:MenuItem Header="rsvp yes" Command="{Binding MainPageViewModel.RsvpYesCommand, Source={StaticResource Locator}}" CommandParameter="{Binding}" />
                                        <toolkit:MenuItem Header="rsvp no" Command="{Binding MainPageViewModel.RsvpNoCommand, Source={StaticResource Locator}}" CommandParameter="{Binding}" />
                                    </toolkit:ContextMenu>
                                </toolkit:ContextMenuService.ContextMenu>


                                <StackPanel Orientation="Horizontal" Width="Auto">
                                    <Image Source="{Binding group.group_photo.thumb_link}" Height="100" Width="100" Stretch="UniformToFill"/>
                                    <StackPanel Orientation="Vertical">
                                        <TextBlock Width="360" Text="{Binding name}" Padding="10,0,0,0" FontSize="{StaticResource PhoneFontSizeMediumLarge}" />
                                        <TextBlock Width="360" Text="{Binding DateTime}" Padding="10,0,0,0" FontSize="{StaticResource PhoneFontSizeSmall}" Foreground="Gray" />
                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>

                </ListBox>

            </controls:PivotItem>


                                                                                                                                                                <controls:PivotItem Header="about" >
                <!--Double line list with text wrapping-->
                <StackPanel Orientation="Vertical">
                    <StackPanel Margin="12,0,0,17" >
                        <StackPanel Visibility="{Binding IsLoggedInVisibility, Mode=OneWay}">
                            <StackPanel>
                                <TextBlock Text="Logged in as: "/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,12,0,0">
                                    
                                <Image Source="{Binding CurrentUser.Photo.thumb_link}" Margin="0,0,12,0" Height="80" Width="80" Stretch="UniformToFill"  VerticalAlignment="Top" HorizontalAlignment="Left"/>
                                <TextBlock Text="{Binding CurrentUser.Name}" Margin="0,0,5,0" Style="{StaticResource PhoneTextExtraLargeStyle}" />
                            </StackPanel>
                        </StackPanel>
                        <StackPanel Visibility="{Binding ShowLoginVisibility, Mode=OneWay}">
                            <Button Content="Log In" Command="{Binding LogInClick}" />
                        </StackPanel>
                        <StackPanel Margin="0,24,0,0">
                            
                            <TextBlock TextWrapping="Wrap" Text="{Binding AboutText}"/>
                            <TextBlock TextWrapping="Wrap">
                                <LineBreak/>For questions, comments, hate mail or support, you can contact me by one of the methods below:
                                <LineBreak/>                                
                            </TextBlock>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock>Twitter: @enloes</TextBlock>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock>Email: </TextBlock>
                                <HyperlinkButton Command="{Binding EmailMeCommand}">senloe-wp7@hotmail.com</HyperlinkButton>
                            </StackPanel>
                            
                            
                        </StackPanel>
                    </StackPanel>
                 </StackPanel>

            </controls:PivotItem>

        </controls:Pivot>
        </Grid>
        <!--<toolkit:PerformanceProgressBar Name="progressBar" VerticalAlignment="Top" IsIndeterminate="{Binding IsWorking}" />-->
    </Grid>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" x:Name="appBar" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/search.png" Text="search" Click="SearchClicked"/>
            <shell:ApplicationBarIconButton IconUri="/Images/set.png" Text="settings" Click="SettingsClicked"/>
            <shell:ApplicationBar.MenuItems>
                <!--<shell:ApplicationBarMenuItem Text="search" Click="SearchClicked" />-->
                <!--<shell:ApplicationBarMenuItem Text="logout" Click="LogoutClicked" />-->                
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>